import * as ActionTypes from './ActionsTypes.js';

export default (state=[],action) =>{
    switch (action.type) {
        case ActionTypes.TODO_ADD:
            return [
                ...state,
                {           
                    type:action.type,
                    text:action.text,           
                    id:action.id
                },
            ]
            break;
            case ActionTypes.TODO_DELETE:
                console.log(action)
                return state.filter((item)=>{
                    return item.id !== action.id
                })
            //filter()方法创建一个新的数组,新数组中的元素
            //注意:filter()不会对空数组进行检测
            //注意:filter()不会改变原始数组
        default:
            return state;
    }
}
